% Settings
dbstop if error;
format compact;
format long;
addpath('compecon/CEtools','compecon/CEdemos','fminsearchbnd','functions', 'moments', 'output')
rehash toolboxcache;

% initialize table to be exported
tab = table(categorical({'clno', 'winner-pretax-1.5%', 'winner-pretax-2.5%', 'household-pretax-2.5%'}'),'VariableNames',{'model'});
tab = addvars(tab, NaN(4,1), 'NewVariableNames', 'mpe');
tab = addvars(tab, NaN(4,1), 'NewVariableNames', 'beta');
tab = addvars(tab, NaN(4,1), 'NewVariableNames', 'delta');

% run CLNO's original specification
[mpe, beta, delta] = estimate('clno'); 
tab.mpe(tab.model == 'clno')   = mpe;
tab.beta(tab.model == 'clno')  = beta;
tab.delta(tab.model == 'clno') = delta;

% match individual pre-tax responses (see their Figure 1), keeping discount rate fixed to 1.5% 
[mpe, beta, delta] = estimate('winner-pretax-1.5%');  % Individual pre-tax, with 1.5p discount rate
tab.mpe(tab.model == 'winner-pretax-1.5%')   = mpe;
tab.beta(tab.model == 'winner-pretax-1.5%')  = beta;
tab.delta(tab.model == 'winner-pretax-1.5%') = delta;

% match individual pre-tax responses (see their Figure 1), keeping discount rate fixed to 2.5% 
[mpe, beta, delta] = estimate('winner-pretax-2.5%');  
tab.mpe(tab.model == 'winner-pretax-2.5%')   = mpe;
tab.beta(tab.model == 'winner-pretax-2.5%')  = beta;
tab.delta(tab.model == 'winner-pretax-2.5%') = delta;

% match household pre-tax responses (see their Figure 5), keeping discount rate fixed to 2.5% 
[mpe, beta, delta] = estimate('household-pretax-2.5%');  
tab.mpe(tab.model == 'household-pretax-2.5%')   = mpe;
tab.beta(tab.model == 'household-pretax-2.5%')  = beta;
tab.delta(tab.model == 'household-pretax-2.5%') = delta;

% export table
writetable(tab, 'output/table.csv')
